package com.jxs.android.sxyw;

import java.text.SimpleDateFormat;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.jxs.android.sxyw.boot.SelfApplication;
import com.jxs.android.sxyw.weiget.PopMsg;
import com.jxs.android.sxyw.weiget.TopBar;
import com.jxs.android.util.StartHelper;
import com.jxs.android.util.StatusHelper;
import com.jxs.android.util.StringUtils;

public abstract class AbstractActivity extends Activity {

	protected String TAG = AbstractActivity.class.getSimpleName();

	protected static SimpleDateFormat SDF_YYYY_MM_dd_HH_mm = new SimpleDateFormat("yyyy-MM-dd HH:mm");

	public void initTopBar(Bundle savedInstanceState, int layoutId) {
		if (!this.getClass().getSimpleName().equals(Login.class.getSimpleName())) {
			if (null == SelfApplication.getUserInfo() || StringUtils.isEmpety(SelfApplication.getUserInfo().getTicket())) {
				PopMsg.show("登录已过期,请重新登录");
				StartHelper.startActivity(Login.class);
				finish();
			}
		}
		if (!StatusHelper.isNetworkAvailable(this)) {
			StatusHelper.checkNetworkAvailable(this);
		}
		super.onCreate(savedInstanceState);
		setContentView(layoutId);
		TopBar topBar = (TopBar) findViewById(R.id.topBar);
		if (null != topBar) {
			topBarLogic(topBar);
		}
	}

	public void topBarLogic(TopBar topBar) {

	}

	public void requestDesDetail(String title, String key) {
		Intent intent = new Intent(this, DescriptionDetail.class);
		Bundle bundle = new Bundle();
		bundle.putString("desc", key);
		bundle.putString("title", title);
		intent.putExtras(bundle);
		startActivity(intent);
	}

	public void requestEditText(String title, String key, int request, int length) {
		Intent intent = new Intent(this, DescriptionSubmit.class);
		Bundle bundle = new Bundle();
		bundle.putString("desc", key);
		bundle.putString("title", title);
		bundle.putInt("length", length);
		intent.putExtras(bundle);
		startActivityForResult(intent, request);
	}

	@Override
	protected void onResume() {
		super.onResume();
		if (!StatusHelper.isNetworkAvailable(this)) {
			StatusHelper.checkNetworkAvailable(this);
			return;
		}
	}

	public void initTopBarReturn(TopBar topBar) {
		if (null != topBar) {
			topBar.setTopBarReturnListern(new TopBar.ReturnBtnListern() {
				@Override
				public void onClickReturn() {
					finish();
				}
			});
		}
	}

}
